export function useRequest() {
  const axios = createAxios({
    baseURL: API_URL,
    cache: 0,
    throttle: true,
    responseData: true,
  });

  axios.onInterceptor(
    () => window.$loadingBar.start(),
    () => window.$loadingBar.finish(),
    () => window.$loadingBar.error()
  );

  axios.onInterceptor401(() => {
    window.$message.error("身份异常, 请重新登录");
  });

  axios.onInterceptor404(() => {
    window.$message.error("资源异常, 请稍后重试");
  });

  axios.onInterceptor500(() => {
    window.$message.error("请求异常, 请稍后重试");
  });

  axios.onInterceptorNetwork(() => {
    window.$message.error("网络异常, 请稍后重试");
  });

  axios.onInterceptorTimeout(() => {
    window.$message.error("资源获取超时, 请稍后重试");
  });

  return axios;
}
